#include"tcpserve.hpp"
#include"log.hpp"
#include"command.hpp"
#include"dict.hpp"
using namespace LogModule;

std::string defaultfunc(std::string mes,InetAddr peer)
{
    return "sreve say@:"+mes;
}
void Usage(std::string proc)
{
    std::cerr << "Usage: " << proc << " port" << std::endl;
}
int main(int argc, char *argv[])
{
    if (argc != 2)
    {
        Usage(argv[0]);
        exit(USAGE_ERR);
    }
    uint16_t port = std::stoi(argv[1]);
    ENABLE_CONSOLE_LOG_STRATEGY();
    //Command comd;
    Dict dit;
    dit.LoadDict();
    std::unique_ptr<tcpserve> tsvr = std::make_unique<tcpserve>(port,[&dit](std::string word,InetAddr peer)->std::string
    {
        return dit.Translate(word,peer);
    });
     
    tsvr->Init();
    tsvr->Run();

    return 0;
}